/**
*	插件：登录
*	开发者：雨中磐石
*	地址：www.rockoa.com
*	日期：2023-07-17
*/

js.login = {
	loginsubmit:function(o1){
		var user = jsform('rockuser').value,pass=jsform('rockpass').value;
		if(!user){
			js.show.error('请输入用户名');return;
		}
		if(!pass){
			js.show.error('请输入密码');return;
		}
		js.show.load('登录中...');
		var odg = jsform('button');
		js.setoption('rockuser', user);
		js.setoption('rockpass', pass);
		
		var da = {user:user,pass:pass,device:device,cfrom:CFROM}		
		js.ajax.post({
			url:'login/check',
			data:da,
			ntoken:true,
			btnobj:odg,
			onsuccess:function(ret){
				js.login.success(ret.data);
			},
			onerror:function(ret){
				
			}
		});
	},
	initv:function(){
		this.ismobile 	= js.web.ismobile();
		jsform('rockuser').value = js.getoption('rockuser');
		jsform('rockpass').value = js.getoption('rockpass');
		VERSION = js.getoption('version', VERSION);
		if(adminface)get('imglogo').src = adminface;
		this.showtitle();
		
		js.ajax.get({
			url:'login/data',
			ntoken:true,
			loading:'加载中...',
			timeout:3000,
			data:{
				url:jm.base64encode(NOWURL)
			}
		},function(ret){
			var ds = ret.data;
			VERSION = ds.version;
			js.setoption('systemtitle', ds.systemtitle);
			js.setoption('findcode', ds.findcode);
			js.setoption('version', VERSION);
			systemtitle = ds.systemtitle;
			js.login.showtitle();
		});
		if(nwjs){
			$('#loginfooter').append('<a clickevt="clear" style="margin-left:10px" class="zhu">清除客户端缓存</a>');
			importjs('nwjs');
		}
		js.initbtn(this);
	},
	showtitle:function(){
		if(this.ismobile)return;
		$('#fontversion').html(systemtitle+''+VERSION+'');
		$('#logintitle').html(systemtitle);
	},
	find:function(){
		js.location(xcy.openurl({
			url:'login/find',
			nlogin:true,
			name:'找回密码'
		}));
	},
	clear:function(){
		js.nwjs.clear();
	},
	success:function(ds){
		js.show.success('登录成功');
		js.setoption('token', ds.token);
		js.setoption('adminname', ds.name);
		js.setoption('usertype', ds.usertype);
		js.setoption('systemtitle', ds.systemtitle);
		js.setoption('adminface', ds.face);
		js.setoption('defnowurl');
		var d = ds.companyinfo;
		if(d){
			if(nwjs)d.hmode=1;
			xcy.opencompany(d, false, true);
		}
		if(this.ismobile){
			var cans = {url:'we/index',name:ds.systemtitle}
			if(d)cans = {url:'we/index',name:d.name,params:{cnum:d.num,title:d.name}};
			js.setoption('defnowurl', cans);
		}
		js.reload();
	}
}